package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author liuchun
 * @since 2024-06-30
 */
@RestController
@RequestMapping("/lessons")
@Api(tags = "用户学习相关接口")
@RequiredArgsConstructor
public class LearningLessonController {

    private final ILearningLessonService learningLessonService;

    /**
     * 分页查询我的课表
     * @param pageQuery
     * @return
     */
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> queryMyLessons(PageQuery pageQuery) {
        return learningLessonService.queryLessons(pageQuery);
    }

    /**
     * 查询正在学习的课表
     * @return
     */
    @GetMapping("/now")
    public LearningLessonVO queryMyCurrentLesson(){
        return learningLessonService.queryMyCurrentLesson();
    }

    /**
     * 检查课程是否有效
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}/valid")
    public Long checkValid(@PathVariable Long courseId){
        return learningLessonService.checkValid(courseId);
    }

    /**
     * 查询用户课表中指定课程状态
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}")
    public LearningLessonVO queryLessonById(@PathVariable Long courseId){
        return learningLessonService.queryLessonById(courseId);
    }

    /**
     * 创建学习计划
     * @param learningPlanDTO
     */
    @ApiOperation("创建学习我的计划")
    @PostMapping("/plans")
    public void createLearningPlans(@RequestBody @Valid LearningPlanDTO learningPlanDTO){
        learningLessonService.createLearningPlans(learningPlanDTO);
    }

    /**
     * 查询学习计划进度
     * @param pageQuery
     * @return
     */
    @ApiOperation("查询学习计划进度")
    @GetMapping("/plans")
    public LearningPlanPageVO queryLearningPlans(PageQuery pageQuery){
        return learningLessonService.queryLearningPlans(pageQuery);
    }
}
